<template>
  <div>

    <vxe_table
      :options="options"
      @handleTableBtn="handleTableBtn"
      ref="baseTable"
    >
      <template #btn>
        <el-button
          type="success"
          icon="el-icon-user"
          @click="add"
          v-permission="['btn_orgUserAdmin_add']"
          >添加组织</el-button
        >
      </template>
    </vxe_table>
    <addDialog ref="add" @success="success"></addDialog>
  </div>
</template>

<script>
import vxe_table from "@/components/table/vxe_table.vue";
import tableMixin from "@/mixins";
import addDialog from "./comps/addDialog.vue";
import { hasBtnAuth, parseTime } from "@/utils";
import { list, del } from "@/api/org";
export default {
  mixins: [tableMixin],
  components: {
    vxe_table,
    addDialog,
  },
  data() {
    return {
      options: {
        id: "orgtabel",
        apiFn: list,
        columns: [
          {
            field: "orgCode",
            title: "商家代码",
            // search: true,
            // valueType: "input",
          },

          {
            field: "name",
            title: "组织名称",
            search: true,
            valueType: "input",
          },
          {
            field: "idUrl",
            title: "身份证",
            type:'html',
            formatter:({row})=>{
              return `<img src="${row.idUrl}" @error="errorHandler" style="width:30px;height:30px"/>`
            }
          },
          { field: "xm", title: "姓名" },
          { field: "note", title: "备注" },
          {
            field: "state",
            title: "状态",
            search: true,
            valueType: "select",
            options: [
              {
                label: "草稿",
                value: 0,
              },
              {
                label: "待审核",
                value: 1,
              },
              {
                label: "正常",
                value: 2,
              },
              {
                label: "已拒绝",
                value: -1,
              },
            ],
            type: "html",
            formatter: ({ row }) => {
              if (row.state == 0) {
                return '<span style="color:#606266">草稿</span>';
              } else if (row.state == 1) {
                return '<span style="color:#409eff">待审核</span>';
              } else if (row.state == 2) {
                return '<span style="color:#67c23a">正常</span>';
              } else if (row.state == -1) {
                return '<span style="color:red">已拒绝</span>';
              }
            },
          },
          {
            field: "createTime",
            title: "时间",
            type: "html",
            formatter: ({ row }) => parseTime(row.createTime),
          },
        ],
        btnWidth: 300,
        btn: [
          {
            title: "编辑",
            handleName: "edit",
            type:'success',
            show: (row) =>
              row.state != -1 && hasBtnAuth("btn_orgUserAdmin_edit"),
          },

          {
            title: "删除",
            handleName: "handleDel",
            type: "danger",
            show: () => hasBtnAuth("btn_orgUserAdmin_del"),
          },
        ],
      },
    };
  },
  methods: {
    handleDel(row) {
      this.$del({ orgCode: row.orgCode }, del);
    },
  },
};
</script>
